package com.huitone.gddw.controller.monitoring;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.huitone.gddw.dao.entity.RedisItem;
import com.huitone.gddw.dao.entity.ReturnedValue;

import com.huitone.gddw.service.RedisItemService;
import com.huitone.gddw.utils.MonitoringResult;

/**
 * redis监控Controller
 * @author lipengfei
 *
 */
@Controller
@RequestMapping(value="redismon")
public class RedisMonitoringController {
	private final static Logger LOGGER = Logger.getLogger(RedisMonitoringController.class);
	
	@Resource
	RedisItemService redisService;
	
	@ResponseBody
	@RequestMapping(value="/selectRedis",method=RequestMethod.POST)
	public MonitoringResult<Map<String, Object>> show(ReturnedValue value){
		MonitoringResult<Map<String, Object>> result = 
				redisService.loadRedis(value);
		LOGGER.info("显示redis监控数据完成");
		return result;
	}
//	@ResponseBody
//	@RequestMapping(value="/selectRedis",method=RequestMethod.POST)
//	public MonitoringResult<List<RedisItem>> select(ReturnedValue returnedValue){
//		MonitoringResult<List<RedisItem>> result = 
//				redisService.select(returnedValue);
//		LOGGER.info("条件查询redis监控数据完成");
//		return result;
//	}
	@ResponseBody
	@RequestMapping(value="/saveIndex",method=RequestMethod.POST)
	public MonitoringResult<RedisItem> save(ReturnedValue returnedValue){
		MonitoringResult<RedisItem> result = 
				redisService.save(returnedValue);
		LOGGER.info("添加redis监控数据完成");
		return result;
	}
//	@ResponseBody
//	@RequestMapping(value="/updataIndex",method=RequestMethod.POST)
//	public MonitoringResult<Map<String,Object>> updata(ReturnedValue value){
//		MonitoringResult<Map<String,Object>> result = 
//				redisService.updata(value);
//		LOGGER.info("更新redis监控数据完成");
//		return result;
//	}
	@ResponseBody
	@RequestMapping(value="/addIndex",method=RequestMethod.POST)
	public MonitoringResult<Map<String, Object>> addIndex(){
		MonitoringResult<Map<String,Object>> result = 
				redisService.addIndex();
		LOGGER.info("添加指标名称完成");
		return result;
	}
	@ResponseBody
	@RequestMapping(value="/showIndex",method=RequestMethod.POST)
	public MonitoringResult<Map<String,Object>> showIndex(ReturnedValue value){
		MonitoringResult<Map<String,Object>> result = 
				redisService.showIndex(value);
		LOGGER.info("获得指标数据完成");
		return result;
	}
	@ResponseBody
	@RequestMapping(value="/allInfo",method=RequestMethod.POST)
	public MonitoringResult<List<Map<String,String>>> getAllInfo(ReturnedValue value){
		MonitoringResult<List<Map<String,String>>> result = 
				redisService.getAllInfo(value);
		LOGGER.info("获得全部指标数据完成");
		return result;
	}
	@ResponseBody
	@RequestMapping(value="/createExcle",method=RequestMethod.POST)
	public MonitoringResult<RedisItem> createExcel(HttpServletResponse response){
		MonitoringResult<RedisItem> result = redisService.createExcel(response);
		System.out.println(result.getMsg());
		LOGGER.info("导出表格完成");
		return result;
	}

}
